@echo off

set R_HOME=%~dp0R
set JRE_HOME=%~dp0jre
set PATH=%JRE_HOME%\bin;%JRE_HOME%\bin\server;%R_HOME%\bin\x64;%PATH%;%HOME%\bin
set CLASSPATH=%CLASSPATH%;%JRE_HOME%\lib;%R_HOME%\library\rJava\jri

set APP_JAR=ispc_desktop.jar

set ID=
    IF "%1%"=="start" GOTO start
    IF "%1%"=="stop" GOTO stop
    IF "%1%"=="restart" GOTO restart
    IF "%1%"=="exit" EXIT
PAUSE

:start
    call :startApp
    GOTO :eof

:stop
    call :stopApp
    GOTO :eof

:restart
    call :stopApp
    call :startApp
    GOTO :eof

:startApp
    IF NOT EXIST "%APP_JAR%" ECHO "%APP_JAR%" is not exist.

    IF EXIST "%APP_JAR%" (
        set "now=%date:~,4%%date:~5,2%%date:~8,2%"
        echo %now%
        java -Xmx1200M -Xms1200M -Xmn500M -Xss256K -XX:SurvivorRatio=3 -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses -XX:MaxTenuringThreshold=3 -XX:AutoBoxCacheMax=20000 -XX:SoftRefLRUPolicyMSPerMB=200 -XX:LargePageSizeInBytes=128M -XX:+UseFastAccessorMethods -Djava.library.path=%R_HOME%\library\rJava\jri -jar %APP_JAR% --spring.profiles.active=dev>> log/ispc_"%now%".log
    )
:stopApp
    IF NOT EXIST "%APP_JAR%" ECHO "%APP_JAR%" is not exist.
    taskkill /F /IM java > nul